<!--  -->
<template>
  <div>
    <s-table
      bordered
      :scroll="{ x: 1000 }"
      :defaultLoad="true"
      ref="table"
      size="default"
      rowKey="id"
      :columns="columns"
      :data="loadData"
      :alert="true"
      show-size-changer
      show-quick-jumper
      :show-pagination="false"
      :loadPage="{
        data: 'data'
      }"
    >
      <span slot="serial" slot-scope="text, record, index">{{ index + 1 }}</span>
      <span slot="auditStatus" slot-scope="text, record">
        {{ handleStatus(record) }}
      </span>
      <template slot="opera" slot-scope="text, record">
        <MoreButton>
        <span><a @click="lookHandler(record, 'look')">查看</a></span>
        <!-- 审核中  审核通过-->
        <span v-if="record.isApprovalButton==1&&record.auditStatus !== 'DRAFT'">
          <a @click="approvaHandler(record)">审批信息</a>
        </span>
        <!-- 待提交 -->
        <!-- 审核不通过 -->
        <template v-if="(record.auditStatus == 'REJECTED' || record.auditStatus == 'DRAFT')&&isDetails == 0" >
          <span @click="lookHandler(record)" v-btn-permission="'pm_029_njh_03'">
            <a>录入年度计划</a>
          </span>
        </template>
          </MoreButton>
      </template>
    </s-table>
    <YearDialog
      :visibleDialog.sync="visibleDialog"
      :yearId.sync="yearId"
      v-bind="$props"
      :yearDialogType="yearDialogType"
      v-on="$listeners"
    ></YearDialog>
    <ApprovalDetails
      :title="'审批详情'"
      :business-id.sync="businessId"
      :visible="visibleApprove"
      @changeBusinessId="changeBusinessId"
      @cancel="visibleApprove = false"
      @confirm="visibleApprove = false"
    />
  </div>
</template>

<script>
import { getOutputYear } from '@/api/project/productionRecords'
import ApprovalDetails from './ApprovaDetails'
import YearDialog from './YearDialog'
export default {
  name: 'YearOutputValue',
  props: ['isDetails'],
  data() {
    return {
      columns: [
        {
          title: '序号',
          width: 65,
          scopedSlots: { customRender: 'serial' }
        },
        {
          title: '年份',
          dataIndex: 'year',
          width: 80
        },
        {
          title: '年度计划产值(项目部制定)(万元)',
          dataIndex: 'yearPlanOutput'
        },
        {
          title: '年度计划产值(分公司修订)(万元)',
          dataIndex: 'yearPlanOutputBC'
        },
        {
          title: '年初累计实际产值（万元）',
          dataIndex: 'yearActualOutput'
        },
        {
          title: '年初累计实际人均产值（万元）',
          dataIndex: 'actualPerCapitaOutput'
        },
        {
          title: '年初累计确权产值（万元）',
          dataIndex: 'confirmOutput'
        },
        {
          title: '年初累计确权人均产值（万元）',
          dataIndex: 'confirmPerCapitaOutput'
        },
        {
          title: '状态',
          width: 120,
          scopedSlots: { customRender: 'auditStatus' }
        },
        {
          title: '操作',
          fixed: 'right',
          width: 150,
          scopedSlots: { customRender: 'opera' }
        }
      ],
      loadData: (parameter) => {
        const requestParameters = Object.assign({}, parameter, { id: this.$route.query.id })
        return getOutputYear(requestParameters).then((res) => {
          return res
        })
      },
      statusList: [
        {
          label: '待提交',
          value: 'DRAFT'
        },
        {
          label: '审核中',
          value: 'SUBMITTED'
        },
        {
          label: '审核通过',
          value: 'PAST'
        },
        {
          label: '分公司已填报',
          value: 'FILLED'
        },
        {
          label: '审核不通过',
          value: 'REJECTED'
        }
      ],
      visibleDialog: false,
      visibleApprove: false,
      businessId: '',
      yearId: '',
      yearDialogType: ''
    }
  },

  components: { YearDialog, ApprovalDetails },

  computed: {},

  created() {},

  watch: {
    visibleApprove(val) {
      if(!val) {
        this.refresh()
      }
    }
  },

  methods: {
    approvaHandler(record) {
      this.businessId = record.id
      this.visibleApprove = true
    },
    changeBusinessId() {},
    refresh() {
      this.$refs.table.refresh(true)
    },
    lookHandler(row, type = 'edit') {
      this.visibleDialog = true
      this.yearId = row.id
      this.yearDialogType = type
    },
    handleStatus(row) {
      return this.statusList.filter((v) => v.value == row.auditStatus)[0].label
    }
  }
}
</script>
<style lang='less' scoped>
/deep/ .ant-table-tbody > tr > td {
  height: 65px;
}
</style>